package com.xlf.common.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;
import com.xlf.cache.RoleList;
import com.xlf.common.model.User;
import com.xlf.web.SessionKey;

public class DesignerInterceptor implements Interceptor {

	@Override
	public void intercept(ActionInvocation ai) {
		Controller controller = ai.getController();
		Integer userType = controller.getSessionAttr(SessionKey.USER_TYPE);
		if(userType == null || userType < 20 || userType > 30) {
			controller.setAttr("notice", "本操作必须使用设计师账号登陆完成");
			controller.redirect("/designer/login");
		} else {
			User user = controller.getSessionAttr(SessionKey.USER);
			controller.setAttr("loginUserName", user.get("name"));
			controller.setAttr("loginUserRole", RoleList.getName(userType));
			
			ai.invoke();
		}
		

	}

}
